class GeneralLedgerAccountController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    static allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
        [ generalLedgerAccountInstanceList: GeneralLedgerAccount.list( params ), generalLedgerAccountInstanceTotal: GeneralLedgerAccount.count() ]
    }

    def show = {
        def generalLedgerAccountInstance = GeneralLedgerAccount.get( params.id )

        if(!generalLedgerAccountInstance) {
            flash.message = "GeneralLedgerAccount not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ generalLedgerAccountInstance : generalLedgerAccountInstance ] }
    }

    def delete = {
        def generalLedgerAccountInstance = GeneralLedgerAccount.get( params.id )
        if(generalLedgerAccountInstance) {
            generalLedgerAccountInstance.delete()
            flash.message = "GeneralLedgerAccount ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "GeneralLedgerAccount not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def generalLedgerAccountInstance = GeneralLedgerAccount.get( params.id )

        if(!generalLedgerAccountInstance) {
            flash.message = "GeneralLedgerAccount not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ generalLedgerAccountInstance : generalLedgerAccountInstance ]
        }
    }

    def update = {
        def generalLedgerAccountInstance = GeneralLedgerAccount.get( params.id )
        if(generalLedgerAccountInstance) {
            if(params.version) {
                def version = params.version.toLong()
                if(generalLedgerAccountInstance.version > version) {
                    
                    generalLedgerAccountInstance.errors.rejectValue("version", "generalLedgerAccount.optimistic.locking.failure", "Another user has updated this GeneralLedgerAccount while you were editing.")
                    render(view:'edit',model:[generalLedgerAccountInstance:generalLedgerAccountInstance])
                    return
                }
            }
            generalLedgerAccountInstance.properties = params
            if(!generalLedgerAccountInstance.hasErrors() && generalLedgerAccountInstance.save()) {
                flash.message = "GeneralLedgerAccount ${params.id} updated"
                redirect(action:show,id:generalLedgerAccountInstance.id)
            }
            else {
                render(view:'edit',model:[generalLedgerAccountInstance:generalLedgerAccountInstance])
            }
        }
        else {
            flash.message = "GeneralLedgerAccount not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def generalLedgerAccountInstance = new GeneralLedgerAccount()
        generalLedgerAccountInstance.properties = params
        return ['generalLedgerAccountInstance':generalLedgerAccountInstance]
    }

    def save = {
        def generalLedgerAccountInstance = new GeneralLedgerAccount(params)
        if(!generalLedgerAccountInstance.hasErrors() && generalLedgerAccountInstance.save()) {
            flash.message = "GeneralLedgerAccount ${generalLedgerAccountInstance.id} created"
            redirect(action:show,id:generalLedgerAccountInstance.id)
        }
        else {
            render(view:'create',model:[generalLedgerAccountInstance:generalLedgerAccountInstance])
        }
    }
}
